package net.luerything.restlet.gwt.rpc.demo.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * @author keke
 */
public class DemoEntry implements EntryPoint {
  public void onModuleLoad() {
    Button button = new Button("Call");
    final HTML html = new HTML();
    FlowPanel panel = new FlowPanel();
    panel.add(button);
    panel.add(html);
    button.addClickHandler(new ClickHandler() {
      public void onClick(final ClickEvent clickEvent) {
        final DemoServiceAsync demoService = GWT.create(DemoService.class);
        ((ServiceDefTarget) demoService).setServiceEntryPoint("/demo.rpc");
        demoService.hello("Restlet", new AsyncCallback<String>() {
          public void onFailure(final Throwable throwable) {
          }

          public void onSuccess(final String s) {
            html.setHTML(s);
          }
        });
      }
    });
    RootPanel.get().add(panel);
  }
}
